/**
 *
 * @param tree
 * @param res
 * @returns {*}
 */
export const getMenuListFromTree = tree => {
  const res = [];
  for (let i = 0; i < tree.length; i++) {
    const menu = tree[i];
    res.push(menu);
    if (menu.children && menu.children.length)
      res.push(...getMenuListFromTree(menu.children));
  }
  return res;
};

/**
 *
 * @param url
 * @returns {{response: {errno: number, data: {url: *}}, url: *}}
 */
export const getFileObjectByUrl = url => {
  return {
    url,
    response: {
      errno: 0,
      data: { url }
    }
  };
};
/**
 *
 * @param area_code
 * @returns {[*]}
 */
// eslint-disable-next-line camelcase
export const getAreaCodeArray = area_code => {
  // eslint-disable-next-line camelcase
  const res = [area_code];
  res.unshift(area_code.substr(0, 4) + "00");
  res.unshift(area_code.substr(0, 2) + "0000");
  return res;
};
/**
 *
 * @param data
 * @returns {string}
 */
export const getJsDataType = data => {
  return Object.prototype.toString.call(data);
};

export const isEmpty = data => {
  const type = getJsDataType(data);
  let res;
  switch (type) {
    case "[object Object]":
      res = Object.keys(data).length === 0;
      break;
    case "[object Null]":
      res = true;
      break;
    case "[object Undefined]":
      res = true;
      break;
    case "[object Array]":
      res = data.length === 0;
      break;
    case "[object String]":
      res =
        data.length === 0 || data === "undefined" || data === "null" || false;
      break;
    default:
      res = false;
  }
  return res;
};
